package com.ljf.task.api.service.impl;

import com.ljf.common.api.service.impl.BasisServiceImpl;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.result.ServiceResultModel;
import com.ljf.common.utils.ServiceResultUtil;
import com.ljf.common.vo.BasicCardTimeLineVO;
import com.ljf.task.domain.repository.TaskDatTaskTabulationRepository;
import com.ljf.task.domain.service.TaskDatTaskTabulationDomainService;
import com.ljf.task.domain.validator.TaskDatTaskTabulationValidator;
import com.ljf.task.dto.command.TaskDatTaskDetailStatusCommand;
import com.ljf.task.dto.command.TaskDatTaskTabulationCommand;
import com.ljf.task.dto.command.TaskDatTaskTabulationDesignCommand;
import com.ljf.task.dto.command.TaskDatTaskTabulationTaskStatusCommand;
import com.ljf.task.dto.query.TaskDatTaskTabulationQuery;
import com.ljf.task.model.TaskDatTaskTabulation;
import com.ljf.task.service.ITaskDatTaskTabulationService;
import com.ljf.task.vo.TaskDatTaskTabulationDesignMessageVO;
import com.ljf.task.vo.TaskDatTaskTabulationDevelopMessageVO;
import com.ljf.task.vo.TaskDatTaskTabulationTaskStatusVO;
import com.ljf.task.vo.TaskDatTaskTabulationVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 任务列表  服务接口实现
 *
 * @author LJF
 * @since 2024-12-25
 */
@Service
public class TaskDatTaskTabulationServiceImpl extends BasisServiceImpl<TaskDatTaskTabulationDomainService, TaskDatTaskTabulationValidator, TaskDatTaskTabulationRepository, TaskDatTaskTabulationQuery, TaskDatTaskTabulationVO, TaskDatTaskTabulation, TaskDatTaskTabulationCommand> implements ITaskDatTaskTabulationService {

    /**
     * 更新任务状态
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editTaskStatus(TaskDatTaskTabulationTaskStatusCommand command) throws ServiceException {
        validator.checkEditTaskStatus(command);
        domainService.editTaskStatus(command);
        return ServiceResultUtil.success();
    }

    /**
     * 获取提交信息文本
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<String> queryCommitMessageById(Long id) throws ServiceException {
        validator.checkQueryCommitMessageById(id);
        List<String> resultList = new ArrayList<>();
        resultList.add(domainService.queryCommitMessageById(id));
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 根据ID查询任务设计信息
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<TaskDatTaskTabulationDesignMessageVO> queryDesignMessageById(Long id) throws ServiceException {
        validator.checkQueryDesignMessageById(id);
        List<TaskDatTaskTabulationDesignMessageVO> resultList = new ArrayList<>();
        resultList.add(domainService.queryDesignMessageById(id));
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 更新任务明细草稿
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editDetailDraft(TaskDatTaskTabulationDesignCommand command) throws ServiceException {
        validator.checkEditDetailDraft(command);
        domainService.editDetailDraft(command);
        return ServiceResultUtil.success();
    }

    /**
     * 更新任务明细终稿
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editDetailFinalDraft(TaskDatTaskTabulationDesignCommand command) throws ServiceException {
        validator.checkEditDetailFinalDraft(command);
        domainService.editDetailFinalDraft(command);
        return ServiceResultUtil.success();
    }

    /**
     * 根据ID查询任务开发信息
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<TaskDatTaskTabulationDevelopMessageVO> queryDevelopMessageById(Long id) throws ServiceException {
        validator.checkQueryDevelopMessageById(id);
        List<TaskDatTaskTabulationDevelopMessageVO> resultList = new ArrayList<>();
        resultList.add(domainService.queryDevelopMessageById(id));
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 更新任务明细开发状态
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editDetailDevelopStatus(TaskDatTaskDetailStatusCommand command) throws ServiceException {
        validator.checkEditDetailDevelopStatus(command);
        domainService.editDetailDevelopStatus(command);
        return ServiceResultUtil.success();
    }

    /**
     * 根据ID查询任务开发提交内容
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<String> queryDetailSubmitMessageById(Long id) throws ServiceException {
        validator.checkQueryDetailSubmitMessageById(id);
        List<String> resultList = new ArrayList<>();
        resultList.add(domainService.queryDetailSubmitMessageById(id));
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 根据ID查询任务状态
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<TaskDatTaskTabulationTaskStatusVO> queryTaskStatusById(Long id) throws ServiceException {
        validator.checkQueryTaskStatusById(id);
        List<TaskDatTaskTabulationTaskStatusVO> resultList = new ArrayList<>();
        resultList.add(domainService.queryTaskStatusById(id));
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 根据ID查询任务操作历史
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<BasicCardTimeLineVO> queryOperateHistoryById(Long id) throws ServiceException {
        validator.checkQueryOperateHistoryById(id);
        return ServiceResultUtil.success(domainService.queryOperateHistoryById(id));
    }

}
